package com.ldl.exam.controllerBack;

import com.github.pagehelper.PageInfo;
import com.ldl.exam.constant.Constants;
import com.ldl.exam.entity.Stu;
import com.ldl.exam.entity.StuExample;
import com.ldl.exam.service.StuService;
import com.ldl.exam.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liudaolin
 * @version 1.0
 * @date 2022/10/20 22:43:23
 */
@RestController
@RequestMapping("/back/stu")
public class StuManageController {
    @Autowired
    private StuService stuService;

    @RequestMapping("/findByPage")
    public AjaxResult findByPage(Integer pageNum, Integer pageSize) {
        if(null == pageSize) {
            pageSize = Constants.DEFAULT_PAGE_SIZE;
        }
        if(null == pageNum) {
            pageNum = Constants.DEFAULT_PAGE_NUM;
        }
        StuExample example = new StuExample();
        //example.or();
        example.setOrderByClause("create_date desc");
        PageInfo<Stu> pageInfo = stuService.findByPage(pageNum, pageSize, example);
        return AjaxResult.isOk("查询成功", pageInfo);
    }

    // 修改状态
    @RequestMapping("/modifyStatusById")
    public AjaxResult modifyStatusById(Integer stuId, Integer status) {
        if(null == status) {
            return AjaxResult.isFail("参数错误");
        }
        switch (status) {
            case -1:
            case 1:
            case 2:
            case 3:
                break;
            default:
                return AjaxResult.isFail("参数错误");
        }
        stuService.modifyStatusById(stuId, status);
        return AjaxResult.isOk("修改成功");
    }

}
